package edu.vt.ece.rt.dstm.contention;

import java.util.Date;

import edu.vt.ece.rt.dstm.Context;

public class Timestamp extends AbstractContentionPolicy{

	@Override
	public void init(Context context) {
//		context.contentionMetadata = new Date().getTime();
	}
	
	@Override
	public int resolve(Context context1, Context context2) {	
		//Use Transaction ID which are based on Time Stamp only
//		Long startTime1 = (Long)context1.contentionMetadata;
//		Long startTime2 = (Long)context2.contentionMetadata;
		
		if(context1.getContextId() > context2.getContextId())
			return +1;						//Priority queue will arrange as head least priority transaction first, so reversed
		else if (context1.getContextId() < context2.getContextId())
			return -1;
		else
			return 0;
	}

	@Override
	public void open(Context context) {}
}
